# 后台任务，如守护线程
import logging
import threading
import time
from pb.service import Service
from fb.updateScoreService import UpdateScoreService

def check_database_condition():
    while True:
        # 在这里添加你的数据库检查逻辑
        print("Checking database condition...")
        time.sleep(60)  # 每60秒检查一次
def prediction():
    service =Service()
    while True:
        try:
            service.run()
            time.sleep(8)
        except Exception as e:
            #print("Response Text:", response.text)
            print(f"请求过程中发生错误：{e}")

def updat_score():
    service =UpdateScoreService()
    while True:
        try:
            service.update()
            print('比分更新成功')
            time.sleep(7200)
        except Exception as e:
            #print("Response Text:", response.text)
            print(f"更新分数出现错误：{e}")

def start_background_tasks():
    # 创建并启动守护线程
    thread = threading.Thread(target=prediction)
    thread.daemon = True  # 设置为守护线程
    thread.start()

    thread2 = threading.Thread(target=updat_score)
    thread2.daemon = True  # 设置为守护线程
    thread2.start()